Component({
  behaviors: ['wx://form-field'],
    externalClasses: ['i-class'],
    relations: {
        '../checkbox/index': {
            type: 'child',
            linked() {
                this.changeCurrent();
            },
            linkChanged() {
                this.changeCurrent();
            },
            unlinked() {
                this.changeCurrent();
            }
        }
    },
    properties: {
        current: {
            type: Array,
            value: [],
            observer: 'changeCurrent'
        },
        key: {
          type: String,
          value: ''
        }
    },
    methods: {
        changeCurrent(val = this.data.current) {
          // console.log('111',val)
            let items = this.getRelationNodes('../checkbox/index');
            const len = items.length;
            if (len > 0) {
                items.forEach(item => {
                    item.changeCurrent(val.indexOf(item.data.value) !== -1);
                });
            }
            this.setData({
              value:val
            })
        },
        emitEvent(current) {
          // console.log('check-current1', this.data.current) 
          // console.log('check-current2',current)
          const index = this.data.current.indexOf(current.value);
          index === -1 ? this.data.current.push(current.value) : this.data.current.splice(index, 1);
          let currentArray = this.data.current.map(item=>item)
          this.setData({current:currentArray})
          let param = { key: this.data.key, value: this.data.current}
          console.log('param',param)
          this.triggerEvent('change', param);
        }
    }
});
